﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using Microsoft.Xna.Framework;

//namespace HexTileBoard
//{
//    public class _QuadtreeLeaf
//    {
//        // Contained objects
//        private Dictionary<HexTileBase, List<TileSimple>> containedBaseTiles;     // List of base tiles contained in this quadtree leaf, used for instanced drawing.
//        private Dictionary<HexTileNaturalModifier, List<TileSimple>> containedNaturalModifiers; // List of natural modifier locations
//        private Dictionary<HexTileManMadeModifier, List<TileSimple>> containedManmadeModifiers; // list of all manmade modifiers
//        private Dictionary<PlayerColor, List<TileSimple>> containedColors;

//        // possible to just draw with Dictionary<key, List<Matrix>>

//        // Leaf components
//        private QuadtreeLeaf[] childLeaves;     // Always 8
//        private BoundingBox ContainerBox;
//        //private Vector2 quadMin, quadMax;       // Maximum bounding dimensions for this leaf.
//        private int nodeDepth;                // Depth of this leaf in the tree.
//        public int NodeDepth
//        {
//            get { return nodeDepth; }
//        }

//        // Tree components
//        private int treeDepth;                // Depth of the tree.
//        public int TreeDepth
//        {
//            get { return treeDepth; }
//        }

//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="_boundingBox">A 1-height bounding box, simulating the 2D XZ quadtree.</param>
//        /// <param name="p_nodeDepth"></param>
//        /// <param name="p_treeDepth"></param>
//        public _QuadtreeLeaf(BoundingBox _boundingBox, int p_nodeDepth, int p_treeDepth)
//        {
//            this.childLeaves = null;
//            this.ContainerBox = _boundingBox;
//            this.ContainerBox.Max.Y = 300;
//            this.ContainerBox.Min.Y = -100;

//            this.nodeDepth = p_nodeDepth;
//            this.treeDepth = p_treeDepth;

//            if (this.nodeDepth != p_treeDepth)
//                Split();
//            else
//            {
//                // Initialize containers for componets drawn with instancing
//                this.containedBaseTiles = new Dictionary<HexTileBase, List<TileSimple>>();
//                foreach (HexTileBase b in InstancedDictionaries.baseListProvider)
//                {
//                    this.containedBaseTiles[b] = new List<TileSimple>();
//                }

//                this.containedNaturalModifiers = new Dictionary<HexTileNaturalModifier, List<TileSimple>>();
//                foreach (HexTileNaturalModifier n in InstancedDictionaries.naturalListProvider)
//                {
//                    this.containedNaturalModifiers[n] = new List<TileSimple>();
//                }

//                this.containedManmadeModifiers = new Dictionary<HexTileManMadeModifier, List<TileSimple>>();
//                foreach (HexTileManMadeModifier m in InstancedDictionaries.manmadeListProvider)
//                {
//                    this.containedManmadeModifiers[m] = new List<TileSimple>();
//                }

//                this.containedColors = new Dictionary<PlayerColor, List<TileSimple>>();
//                foreach (PlayerColor p in InstancedDictionaries.colorListProvider)
//                {
//                    this.containedColors[p] = new List<TileSimple>();
//                }
//            }
//        }

//        public void DrawVisibleInstancedListsByDiscovery(GameTime gameTime, SimpleCamera camera, bool _creatingShadows)
//        {
//            //BoardConstructor.branchesVisited++;

//            // If our camera intersects this box...
//            if (camera.ViewFrustum.Intersects(this.ContainerBox))
//            {
//                // ... and we are at the child leaves at the bottom of the tree
//                if (this.nodeDepth == treeDepth)
//                {
//                    // ... so loop through dictionaries and draw.
//                    // ----------------------------------------------------------------
//                    // Draw Color tiles
//                    // ----------------------------------------------------------------
//                    //foreach (PlayerColor p in InstancedDictionaries.colorListProvider)
//                    //{
//                    //    if (p == PlayerColor.None)
//                    //        continue;

//                    //    //BoardConstructor.objectsDrawn += this.containedColors[p].Count;

//                    //    // For each model, gather all the instance transform (world) matrices into a single array.
//                    //    Array.Resize(ref InstancedDictionaries.colorModels[p].instanceTransforms, this.containedColors[p].Count);

//                    //    // Original version, for single threaded.
//                    //    for (int i = 0; i < this.containedColors[p].Count; i++)
//                    //    {
//                    //        // TEMP: just double check the count to prevent resize issues
//                    //        // Also, can lock resize when updating and unlock when done, but only works with a 0 level quadtree
//                    //        //if (InstancedDictionaries.colorModels[p].instanceTransforms.Length == this.containedColors[p].Count)
//                    //            InstancedDictionaries.colorModels[p].instanceTransforms[i] = Matrix.CreateScale(1.0f, 4.0f * this.containedColors[p][i].value, 1.0f) * Matrix.CreateTranslation(new Vector3(0, 10 * (this.containedColors[p][i].value), 0)) * this.containedColors[p][i].ModelMatrix;
//                    //    }

//                    //    //--------------------------------------------
//                    //    // Create the shadow map
//                    //    //--------------------------------------------
//                    //    if (_creatingShadows)
//                    //    {
//                    //        //if (InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow)
//                    //        //{
//                    //        //    // Draw any occluders to the shadow map
//                    //        //    switch (InstancedDrawing.instancingTechnique)
//                    //        //    {
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapHardwareInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;
//                    //        //    }
//                    //        //}
//                    //    }
//                    //    else
//                    //    {
//                    //        //--------------------------------------------
//                    //        // Draw with the shadow map. DO NOT SHADOW COLOR TILES
//                    //        //--------------------------------------------
//                    //        switch (InstancedDrawing.instancingTechnique)
//                    //        {
//                    //            // No shadow techniques
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow:
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "HardwareInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingNoShadow:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.colorModels[p].instancedModel, InstancedDictionaries.colorModels[p].instancedModelBones, InstancedDictionaries.colorModels[p].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //        }
//                    //    }
//                    //}

//                    // ----------------------------------------------------------------
//                    // Draw base tiles
//                    // ----------------------------------------------------------------
//                    foreach (HexTileBase b in InstancedDictionaries.baseListProvider)
//                    {
//                        //BoardConstructor.objectsDrawn += this.containedBaseTiles[b].Count;

//                        // For each model, gather all the instance transform (world) matrices into a single array.
//                        Array.Resize(ref InstancedDictionaries.baseModels[b].instanceTransforms, this.containedBaseTiles[b].Count);
//                        for (int i = 0; i < this.containedBaseTiles[b].Count; i++)
//                        {
//                            InstancedDictionaries.baseModels[b].instanceTransforms[i] = this.containedBaseTiles[b][i].ModelMatrix;
//                        }

//                        //--------------------------------------------
//                        // Create the shadow map
//                        //--------------------------------------------
//                        if (_creatingShadows)
//                        {
//                            if (InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow &&
//                                InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingNoShadow &&
//                                InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow)
//                            {
//                                // Draw any occluders to the shadow map
//                                switch (InstancedDrawing.instancingTechnique)
//                                {
//                                    case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                                    case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                                    case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                                    case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                                        InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                            "CreateShadowMapHardwareInstancing", true, 1.0f);
//                                        break;

//                                    case InstancedDrawing.InstancingTechnique.NoInstancing:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                                        InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                            "CreateShadowMapNoInstancing", true, 1.0f);
//                                        break;

//                                    case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                                    case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                                        InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                            "CreateShadowMapNoInstancing", true, 1.0f);
//                                        break;
//                                }
//                            }
//                        }
//                        else
//                        {
//                            //--------------------------------------------
//                            // Draw with the shadow map
//                            //--------------------------------------------
//                            switch (InstancedDrawing.instancingTechnique)
//                            {
//                                // No shadow techniques
//                                case InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow:
//                                    InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "HardwareInstancingNoShadow", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancingNoShadow:
//                                    InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "NoInstancingNoShadow", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow:
//                                    InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "NoInstancingNoShadow", false, 1.0f);
//                                    break;

//                                // Shadow techniques
//                                case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                                    InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapHardwareInstancing", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                                    InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                                    InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                                    InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapHardwareInstancing7x7", false, 1.0f);
//                                    break;

//                                case InstancedDrawing.InstancingTechnique.NoInstancing:
//                                    InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                                    InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                                    InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                                    InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                                    break;

//                                case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                                    InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                                    InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                                    InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                                    break;
//                                case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                                    InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.baseModels[b].instancedModel, InstancedDictionaries.baseModels[b].instancedModelBones, InstancedDictionaries.baseModels[b].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                                        "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                                    break;
//                            }
//                        }
//                    }

//                    //// ----------------------------------------------------------------
//                    //// Draw natural modifiers
//                    //// ----------------------------------------------------------------
//                    //// ... so loop through dictionaries and draw.
//                    //foreach (HexTileNaturalModifier n in InstancedDictionaries.naturalListProvider)
//                    //{
//                    //    if (n == HexTileNaturalModifier.None)
//                    //        continue;

//                    //    //BoardConstructor.objectsDrawn += this.containedNaturalModifiers[n].Count;

//                    //    // For each model, gather all the instance transform (world) matrices into a single array.
//                    //    Array.Resize(ref InstancedDictionaries.naturalModifierModels[n].instanceTransforms, this.containedNaturalModifiers[n].Count);
//                    //    for (int i = 0; i < this.containedNaturalModifiers[n].Count; i++)
//                    //    {
//                    //        InstancedDictionaries.naturalModifierModels[n].instanceTransforms[i] = this.containedNaturalModifiers[n][i].naturalMatrix;
//                    //    }

//                    //    //--------------------------------------------
//                    //    // Create the shadow map
//                    //    //--------------------------------------------
//                    //    if (_creatingShadows)
//                    //    {
//                    //        //if (InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow)
//                    //        //{
//                    //        //    // Draw any occluders to the shadow map
//                    //        //    switch (InstancedDrawing.instancingTechnique)
//                    //        //    {
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapHardwareInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;
//                    //        //    }
//                    //        //}
//                    //    }
//                    //    else
//                    //    {
//                    //        //--------------------------------------------
//                    //        // Draw with the shadow map
//                    //        //--------------------------------------------
//                    //        switch (InstancedDrawing.instancingTechnique)
//                    //        {
//                    //            // No shadow techniques
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "HardwareInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingNoShadow:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;

//                    //            // Shadow techniques
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing7x7", false, 1.0f);
//                    //                break;

//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                    //                break;

//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.naturalModifierModels[n].instancedModel, InstancedDictionaries.naturalModifierModels[n].instancedModelBones, InstancedDictionaries.naturalModifierModels[n].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                    //                break;
//                    //        }
//                    //    }
//                    //}

//                    //// ----------------------------------------------------------------
//                    //// Draw manmade modifiers
//                    //// ----------------------------------------------------------------
//                    //// ... so loop through dictionaries and draw.
//                    //foreach (HexTileManMadeModifier m in InstancedDictionaries.manmadeListProvider)
//                    //{
//                    //    if (m == HexTileManMadeModifier.None)
//                    //        continue;

//                    //    //BoardConstructor.objectsDrawn += this.containedManmadeModifiers[m].Count;

//                    //    // For each model, gather all the instance transform (world) matrices into a single array.
//                    //    Array.Resize(ref InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, this.containedManmadeModifiers[m].Count);
//                    //    for (int i = 0; i < this.containedManmadeModifiers[m].Count; i++)
//                    //    {
//                    //        InstancedDictionaries.manMadeModifierModels[m].instanceTransforms[i] = this.containedManmadeModifiers[m][i].ModelMatrix;
//                    //    }

//                    //    //--------------------------------------------
//                    //    // Create the shadow map
//                    //    //--------------------------------------------
//                    //    if (_creatingShadows)
//                    //    {
//                    //        //if (InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingNoShadow &&
//                    //        //    InstancedDrawing.instancingTechnique != InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow)
//                    //        //{
//                    //        //    // Draw any occluders to the shadow map
//                    //        //    switch (InstancedDrawing.instancingTechnique)
//                    //        //    {
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapHardwareInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;

//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //        //        case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //        //            InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //        //                "CreateShadowMapNoInstancing", true, 1.0f);
//                    //        //            break;
//                    //        //    }
//                    //        //}
//                    //    }
//                    //    else
//                    //    {
//                    //        //--------------------------------------------
//                    //        // Draw with the shadow map
//                    //        //--------------------------------------------
//                    //        switch (InstancedDrawing.instancingTechnique)
//                    //        {
//                    //            // No shadow techniques
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancingNoShadow:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "HardwareInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingNoShadow:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatchingNoShadow:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "NoInstancingNoShadow", false, 1.0f);
//                    //                break;

//                    //            // Shadow techniques
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing3x3:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing5x5:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.HardwareInstancing7x7:
//                    //                InstancedDrawing.DrawModelHardwareInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapHardwareInstancing7x7", false, 1.0f);
//                    //                break;

//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing3x3:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing5x5:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancing7x7:
//                    //                InstancedDrawing.DrawModelNoInstancing(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                    //                break;

//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching3x3:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching5x5:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing3x3", false, 1.0f);
//                    //                break;
//                    //            case InstancedDrawing.InstancingTechnique.NoInstancingOrStateBatching7x7:
//                    //                InstancedDrawing.DrawModelNoInstancingOrStateBatching(InstancedDictionaries.instancedGraphicsDevice, InstancedDictionaries.manMadeModifierModels[m].instancedModel, InstancedDictionaries.manMadeModifierModels[m].instancedModelBones, InstancedDictionaries.manMadeModifierModels[m].instanceTransforms, camera.ViewMatrix, camera.ProjectionMatrix,
//                    //                    "DrawWithShadowMapNoInstancing7x7", false, 1.0f);
//                    //                break;
//                    //        }
//                    //    }
//                    //}
//                }
//                else    // ... else search our children through recursion.
//                {
//                    for (int i = 0; i < 4; i++)
//                        childLeaves[i].DrawVisibleInstancedListsByDiscovery(gameTime, camera, _creatingShadows);
//                }
//            }
//            else
//            {
//                return;
//            }
//        }

//        public void RetrieveIntersectedObjects(Ray cursorRay, ref List<TileSimple> retrievedTiles)
//        {
//            // If our camera intersects this box...
//            if (cursorRay.Intersects(this.ContainerBox) != null)
//            {
//                // ... and we are at the child leaves at the bottom of the tree
//                if (this.nodeDepth == treeDepth)
//                {
//                    // ... so loop through dictionaries and draw.
//                    foreach (HexTileBase b in InstancedDictionaries.baseListProvider)
//                    {
//                        for (int i = 0; i < this.containedBaseTiles[b].Count; i++)
//                        {
//                            if (this.containedBaseTiles[b][i].BS.Intersects(cursorRay) != null)
//                            {
//                                // add to list
//                                retrievedTiles.Add(this.containedBaseTiles[b][i]);
//                            }
//                        }
//                    }
//                }
//                else    // ... else search our children through recursion.
//                {
//                    for (int i = 0; i < 4; i++)
//                        childLeaves[i].RetrieveIntersectedObjects(cursorRay, ref retrievedTiles);
//                }
//            }
//            else
//            {
//                return;
//            }
//        }

//        public void RetrieveClosestObject(Ray cursorRay, ref TileSimple closestTile)
//        {
//            // If our camera intersects this box...
//            if (cursorRay.Intersects(this.ContainerBox) != null)
//            {
//                // ... and we are at the child leaves at the bottom of the tree
//                if (this.nodeDepth == treeDepth)
//                {
//                    // ... so loop through dictionaries and draw.
//                    foreach (HexTileBase b in InstancedDictionaries.baseListProvider)
//                    {
//                        for (int i = 0; i < this.containedBaseTiles[b].Count; i++)
//                        {
//                            if (this.containedBaseTiles[b][i].BS.Intersects(cursorRay) != null)
//                            {
//                                if (closestTile == null)
//                                {
//                                    closestTile = this.containedBaseTiles[b][i];
//                                }
//                                else if (Vector3.Distance(cursorRay.Position, closestTile.Position) > Vector3.Distance(cursorRay.Position, this.containedBaseTiles[b][i].Position))
//                                {
//                                    closestTile = this.containedBaseTiles[b][i];
//                                }
//                            }
//                        }
//                    }
//                }
//                else    // ... else search our children through recursion.
//                {
//                    for (int i = 0; i < 4; i++)
//                        childLeaves[i].RetrieveClosestObject(cursorRay, ref closestTile);
//                }
//            }
//            else
//            {
//                return;
//            }
//        }

//        public bool AddColorTile(TileSimple hexTile)
//        {
//            if (hexTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    this.containedColors[hexTile.tileOwner].Add(hexTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].AddColorTile(hexTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        public bool AddBaseTile(TileSimple hexTile)
//        {
//            if (hexTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    this.containedBaseTiles[hexTile.TileBase].Add(hexTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].AddBaseTile(hexTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        public bool AddNaturalModifier(TileSimple baseTile)
//        {
//            if (baseTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    // Randomize the rotation of natural objects, if not wheat
//                    Matrix r = Matrix.Identity;
//                    if (baseTile.NaturalModifier != HexTileNaturalModifier.Wheat)
//                    {
//                        baseTile.naturalRotationAmount = BoardConstructor.random.Next(0, 700) / 100.0f;
//                        r = Matrix.CreateRotationY(baseTile.naturalRotationAmount);
//                    }
//                    baseTile.naturalMatrix = r * baseTile.ModelMatrix;

//                    this.containedNaturalModifiers[baseTile.NaturalModifier].Add(baseTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].AddNaturalModifier(baseTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        public bool AddManmadeModifier(TileSimple baseTile)
//        {
//            if (baseTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    this.containedManmadeModifiers[baseTile.ManMadeModifier].Add(baseTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].AddManmadeModifier(baseTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        public bool RemoveNaturalModifier(TileSimple baseTile)
//        {
//            if (baseTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    // remove the rotations added for natural modifiers
//                    this.containedNaturalModifiers[baseTile.PreviousNaturalModifier].Remove(baseTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].RemoveNaturalModifier(baseTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        public bool RemoveManMadeModifier(TileSimple baseTile)
//        {
//            if (baseTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    // remove the rotations added for natural modifiers
//                    this.containedManmadeModifiers[baseTile.PreviousManMadeModifier].Remove(baseTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].RemoveManMadeModifier(baseTile))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }


//        /// <summary>
//        /// Removes a colored tile from the draw queue.
//        /// </summary>
//        /// <param name="baseTile"></param>
//        /// <param name="previousOwner">Needed as the tile's owner is cleared before the quadtree is removed.</param>
//        /// <returns></returns>
//        public bool RemoveColor(TileSimple baseTile, PlayerColor previousOwner)
//        {
//            if (baseTile.BS.Intersects(this.ContainerBox))
//            {
//                if (this.nodeDepth == this.treeDepth)    // only add to the bottom of the tree
//                {
//                    // remove the rotations added for natural modifiers
//                    this.containedColors[previousOwner].Remove(baseTile);
//                    return true;
//                }
//                else
//                {
//                    for (int i = 0; i < 4; i++)
//                    {
//                        if (childLeaves[i].RemoveColor(baseTile, previousOwner))
//                        {
//                            return true;
//                        }
//                    }
//                    return false;
//                }
//            }
//            else
//            {
//                return false;
//            }
//        }

//        private void Split()
//        {
//            Vector3 half = ContainerBox.Max - ContainerBox.Min;
//            half *= 0.5f;
//            Vector3 halfx = Vector3.UnitX * half;
//            Vector3 halfz = Vector3.UnitZ * half;

//            childLeaves = new QuadtreeLeaf[4];
//            childLeaves[0] = new QuadtreeLeaf(new BoundingBox(ContainerBox.Min, ContainerBox.Min + half), this.nodeDepth + 1, this.treeDepth);
//            childLeaves[1] = new QuadtreeLeaf(new BoundingBox(ContainerBox.Min + halfx, ContainerBox.Max - halfz), this.nodeDepth + 1, this.treeDepth);
//            childLeaves[2] = new QuadtreeLeaf(new BoundingBox(ContainerBox.Min + halfz, ContainerBox.Max - halfx), this.nodeDepth + 1, this.treeDepth);
//            childLeaves[3] = new QuadtreeLeaf(new BoundingBox(ContainerBox.Min + half, ContainerBox.Max), this.nodeDepth + 1, this.treeDepth);


//            //Vector2 half = quadMax - quadMin;
//            //half *= 0.5f;
//            //Vector2 halfx = Vector2.UnitX * half;
//            //Vector2 halfy = Vector2.UnitY * half;

//            //childLeaves = new QuadtreeLeaf[4];
//            //childLeaves[0] = new QuadtreeLeaf(quadMin, quadMin + half, (short)(this.nodeDepth + 1), this.treeDepth);
//            //childLeaves[1] = new QuadtreeLeaf(quadMin + halfx, quadMax - halfy, (short)(this.nodeDepth + 1), this.treeDepth);
//            //childLeaves[2] = new QuadtreeLeaf(quadMin + halfy, quadMax - halfx, (short)(this.nodeDepth + 1), this.treeDepth);
//            //childLeaves[3] = new QuadtreeLeaf(quadMin + half, quadMax, (short)(this.nodeDepth + 1), this.treeDepth);
//        }
//    }
//}
